import {env, service} from "@/utils";
import {Ref} from "vue";

export const getDictTrim = (table: string, field?: string) => service.get('/dict/trim', {tableName: table, fieldName: field})

export const getUriTrim = (category: string) => service.get('/setting/uri/trim', {category: category})

export const getRoleList = (alias?: string) => service.get<RowData>('/role', {alias: alias})

export const getDeptTree = ()=> service.get<RowData>('/dept')

export const getMenuTree = () => service.get<RowData>('/menu');

export const getMenuTreeByType = (type = '0,2') => service.get('/menu', {type: type});

export const getMenuPermissionsByRole = (roles: any[]) => service.get('/role/menu', {roleId: roles})

export const getModuleListByStatus = (status: number[])=> service.get('/module/list', {status: status})

export const getPrimaryModuleList = (primary = true, name?: string)=> service.get('/module/name', {name: name, primary: primary})

export const getRunLogContent = (form: {lines: number, uri: string}, content: Ref): void => {
    if (env.APP_VERSION === '3.0.0') {
        service.get('actuator/logger', {lines: form.lines}).then(data => {
            if (data) {
                content.value = ''
                data.forEach((item: string) =>{
                    content.value += item + '\n';
                })
            }
        })
    } else {
        service.get('/log/run', {lines: form.lines, uri: form.uri}).then(({data}) =>{
            content.value = ''
            // let level = 'INFO';
            data.forEach((item: string) =>{
                // if (item.includes( 'ERROR')) level = 'ERROR';
                // if (item.includes( 'INFO')) level = 'INFO';
                // if (item.includes( 'DEBUG')) level = 'DEBUG';
                // if (item.includes( 'WARN')) level = 'WARN';
                // let p = level === 'ERROR'?'<p style="color: #F56C6C">': level === 'WARN'? '<p style="color: #E6A23C">':'<p>';
                // content.value += p + item + '</p>';
                content.value += item + '\n';
            })
        })
    }
}

export const getRunLogDir = (uri: string, path?: string) => service.get('/log/dir', { path: path, uri: uri})
